<?php
// +----------------------------------------------------------------------
//            -------------------------
//           /   / ----------------\  \
//          /   /             \  \
//         /   /              /  /
//        /   /    /-------------- /  /
//       /   /    /-------------------\  \
//      /   /                   \  \
//     /   /                     \  \
//    /   /                      /  /
//   /   /      /----------------------- /  /
//  /-----/      /---------------------------/
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://baimifan.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: Sage 2016/4/22  16:46
// +----------------------------------------------------------------------
namespace Admin\Controller;
class CardFreezeController extends CashierBaseController {

    function index() {
        $this->display();
    }

    //挂失冻结
    function doFreeze() {
        $data = I("post.");
        $Card=M("Card");
        $map=[
            "card_id"=>$data['card_id']
        ];
        $d=$Card->where($map)->find();
        if(!$d){
            $j=[
                "status"=>"error",
                "data"=>"此卡不存在"
            ];
            echo json_encode($j);
            return;
        }
        if($d['is_lock']==-1){
            $j=[
                "status"=>"error",
                "data"=>"此卡已冻结,不要重复操作"
            ];
            echo json_encode($j);
            return;
        }
        $map_card=[
            "is_lock"=>-1,
            "remark"=>$d['remark']."于".date("Y-m-d h:i:s")."冻结;<br>"
        ];
        $r=$Card->where($map)->data($map_card)->save();
        if($r){
            $j=[
                "status"=>"success",
                "data"=>"冻结成功"
            ];
            echo json_encode($j);
            return;
        }else{
            $j=[
                "status"=>"error",
                "data"=>"冻结失败"
            ];
            echo json_encode($j);
            return;
        }
    }

    function doUnFreeze(){
        $data = I("post.");
        $Card=M("Card");
        $map=[
            "card_id"=>$data['card_id']
        ];
        $d=$Card->where($map)->find();
        if(!$d){
            $j=[
                "status"=>"error",
                "data"=>"此卡不存在"
            ];
            echo json_encode($j);
            return;
        }
        if($d['is_lock']==0){
            $j=[
                "status"=>"error",
                "data"=>"此卡已解冻,不要重复操作"
            ];
            echo json_encode($j);
            return;
        }
        $map_card=[
            "is_lock"=>0,
            "remark"=>$d['remark']."于".date("Y-m-d h:i:s")."解除冻结;<br>"
        ];
        $r=$Card->where($map)->data($map_card)->save();
        if($r){
            $j=[
                "status"=>"success",
                "data"=>"解除成功"
            ];
            echo json_encode($j);
            return;
        }else{
            $j=[
                "status"=>"error",
                "data"=>"解除失败"
            ];
            echo json_encode($j);
            return;
        }
    }

    function cardShow() {
        $card_id = I("get.card_id");
        $d = M("Card")->where(["card_id" => $card_id])->find();
        if ($d) {
            $d['child_sex'] = $d['child_sex'] == 1 ? "男" : "女";
            $d['is_lock'] = $d['is_lock'] == -1 ? "冻结" : "非冻结";
        }
        $this->assign("d" , $d);
        $this->display("CardHandle:cardShow");
    }
}